package 字节;

import java.util.Arrays;

/**
 * @author zz
 * @Date 2022/6/7
 * 221
 */

public class 最大正方形 {
    public static int maximalSquare(char[][] matrix) {
       int maxside=0;
       if(matrix==null||matrix.length==0||matrix[0].length==0){
           return maxside;
       }
       int m=matrix.length;
       int n=matrix[0].length;
       int[][] dp=new int[m][n];

       for (int i=0;i<matrix.length;i++){
           for(int j=0;j<matrix[0].length;j++){
               if(matrix[i][j]=='1'){
                   if(i==0||j==0){
                       dp[i][j]=1;
                   }else {
                       dp[i][j]=Math.min(Math.min(dp[i-1][j],dp[i-1][j-1]),dp[i][j-1])+1;
                   }

               }
               maxside=Math.max(maxside,dp[i][j]);


       }



}
       return maxside*maxside;
    }

    public static void main(String[] args) {
        char[][] matrixmatrix = {{'1','0','1','0','0'},{'1','0','1','1','1'},{'1','1','1','1','1'},{'1','0','0','1','0'}};
        System.out.println(maximalSquare(matrixmatrix));

    }
}
